<?php
abstract class Tv_Arte_Nav_ARenderer
{
    /**
     * @var     Tv_Arte_Nav_Iterator
     */
    private $_it = null;
    /**
     * Constructeur
     */
    public function  __construct()
    {

    }
    /**
     * setIterator
     *
     * @param   Tv_Arte_Nav_Iterator $it
     * @return  void
     */
    public function setIterator(Tv_Arte_Nav_Iterator $it)
    {
        $this->_it = $it;
    }
    /**
     * getIterator
     *
     * @return  Tv_Arte_Nav_Iterator
     */
    public function getIterator()
    {
        return $this->_it;
    }
    /**
     * getNodeStart
     *
     * @return  String
     */
    abstract public function getNodeStart();
    /**
     * getNodeContentStart
     *
     * @return  String
     */
    abstract public function getNodeContentStart();
    /**
     * getNodeContentEnd
     *
     * @return  String
     */
    abstract public function getNodeContentEnd();
    /**
     * getNodeEnd
     *
     * @return  String
     */
    abstract public function getNodeEnd();
    /**
     * Noeud de contenu par default
     *
     * @return  String
     */
    abstract public function getNodeContent();
    /**
     * render
     * @static
     * @param Tv_Arte_Nav_ARenderer $renderer
     * @param Tv_Arte_Nav_Iterator $it
     * @param Integer $prevDepth
     * @return string
     */
    public static function render(Tv_Arte_Nav_ARenderer $renderer, Tv_Arte_Nav_Iterator $it, $prevDepth)
    {
        $html = "";
        $renderer->setIterator($it);
        if ($it->count() > 0) {
            $tabs = $it->getTabs($prevDepth);
            $html .= $tabs[0] . $renderer->getNodeStart();
            foreach ($it as $key => $value) {/* @var $value Tv_Arte_Nav_AComponent */
                $componentData = $value->getComponentData();/* @var $componentData Tv_Arte_Nav_IComponentData */
                $data = $componentData->getData();
                $depth = $componentData->getDepth();
                $html .= $tabs[1] . $renderer->getNodeContentStart() . "\n";
                $html .= $renderer->getNodeContent() . "\n";
                if ($it->hasChildren()) {
                    $html .= self::render(clone($renderer), new Tv_Arte_Nav_Iterator($value->getChildren()), $depth);
                }
                $html .= $tabs[1] . $renderer->getNodeContentEnd() . "\n";
            }
            $html .= $tabs[0] . $renderer->getNodeEnd() . "\n";
        }
        return $html;
    }
}